package com.starbaba.invitate.view;

import com.opensymphony.xwork2.ModelDriven;
import com.starbaba.core.utils.PropertyParamMapBuilder;
import com.starbaba.core.utils.Struts2Utils;
import com.starbaba.core.utils.json.JsonUtils;
import com.starbaba.core.web.page.PageResponse;
import com.starbaba.core.web.struts2.BaseAction;
import com.starbaba.invitate.model.UserInvitateDetails;
import com.starbaba.invitate.service.UserInvitateDetailsService;
import com.tuanzi.server.loan_base.util.PhoneNumNideUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.ArrayList;
import java.util.List;


@SuppressWarnings({"rawtypes", "unchecked", "serial"})
public class UserInvitateDetailsAction extends BaseAction implements ModelDriven<UserInvitateDetails>{

	private UserInvitateDetailsService service;
	
	@Autowired
	@Qualifier("userInvitateDetailsService")
	public void setService(UserInvitateDetailsService service) {
		this.service = service;
	}
	
	public String showPage() throws Exception{
		return "success";
	}
	
	public void queryList(){
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		parsePageRequest();
		PageResponse pageResponse = new PageResponse();
		int start = pageRequest.getIDisplayStart();
		int length = pageRequest.getIDisplayLength();

		try {
			List<UserInvitateDetails> list = new ArrayList<UserInvitateDetails>();
			list = service.getList(start, length, pageResponse, paramsMap);
			//对电话中间四位转为*
			for (int i = 0; i <list.size() ; i++) {
				UserInvitateDetails userInvitateDetails= list.get(i);
				userInvitateDetails.setInvitatorMobile(PhoneNumNideUtil.hideNum(userInvitateDetails.getInvitatorMobile()));
				userInvitateDetails.setInviteeMobile(PhoneNumNideUtil.hideNum(userInvitateDetails.getInviteeMobile()));
				list.set(i,userInvitateDetails);
			}
			pageResponse.setAaData(list);
			pageResponse.setSEcho(pageRequest.getSEcho());

			sendJsonMessage(JsonUtils.toJson(pageResponse, null, true, null, false));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public UserInvitateDetails getModel() {
		
		return null;
	}
	
}
